using System;

namespace armcontrolgui
{
	public class Axis
	{
		public delegate void AxisDelegate(Axis Sender);
		public event AxisDelegate PositionUpdated;
		
		public readonly int Index;
		public readonly string Name;
		public readonly double Minimum;
		public readonly double Maximum;
		
		private double do_Pos;
		
		public Axis(int MyIndex, string MyName, double MyMinimum, double MyMaximum)
		{
			if(MyMaximum <= MyMinimum)
				throw new ArgumentOutOfRangeException("MyMaximum");
			
			this.Index = MyIndex;
			this.Name = MyName;
			this.Minimum = MyMinimum;
			this.Maximum = MyMaximum;
			this.do_Pos = this.Center;
		}
		
		public double Position {
			get {
				return this.do_Pos;
			}
			set {
				if(value > this.Maximum || value < this.Minimum)
					throw new ArgumentOutOfRangeException("value");
				
				if(this.do_Pos == value)
					return;
				
				this.do_Pos = value;
				if(this.PositionUpdated != null)
					this.PositionUpdated(this);
			}
		}
		
		public double Center {
			get { return this.Minimum + ((this.Maximum - this.Minimum) / 2); }
		}
	}
}
